#!/usr/bin/python3
# -*- coding:utf-8 -*-
""""
@Author: lijk34925
@Time: 2024/3/7 16:14
@File: sqlChange.py
"""

import re


class sqlChange:
    def __init__(self,sql):
        self.sql = sql

    def remove_time(self):
        sql_list = re.split(r"(?i)values",self.sql)
        keys = sql_list[0].lower().split(',')
        keys = [key.strip() for key in keys]
        values =[value.strip() for value in sql_list[1].split(',') if value.strip() != '']
        index = [i for i in range(len(keys)) if "_time" in keys[i]]
        print(index)
        for i in index:
            keys.pop(i)
            values.pop(i)
        key_result = ",".join(keys)
        value_result = ",".join([value if value != '' else "''" for value in values])
        if len(keys) in index:
            key_result = +")"
            value_result = +");"
        print(key_result+' values '+value_result)
        return key_result+' values '+value_result

if __name__ == '__main__':
    sql = "INSERT INTO hsfund.fnd_fund_account(occur_date, fund_account, client_full_name, benefit_name, benefit_tel, transactor_birthday, company_tel, home_tel, manger_id_no, manager_id_type, client_type, shareholder_type, id_effective_maturity, fund_acc_status, contact_address, agency_no, actual_benefit_id_no, actual_benefit_id_type, actual_benefit_name, birth_place, birth_date, broker, business_scope, business_country_code, transactor_address, transactor_cellphone_num, transactor_nationality_code, transactor_name, relation_type, transactor_id_type, transactor_id_no, transactor_office_address, actual_control_id_no, actual_control_id_type, actual_control_name, work_unit, work_unit_tel, client_name, client_id, education_code, email_address, fax_number, id_address, id_no, id_type, annual_income, income_source, income_source_supply, industry_name, industry_code, unified_social_credit_code, legp_email, legp_cellphone_number, legp_name, principal_name, principal_id_no, principal_id_type, manager_name, remarks, cellphone_number, nationality_code, branch_no, telephone_number, referee_id, register_address, gender_code, ta_no, tax_register_no, tax_register_id_type, trade_account, occupation_code, occupation_supply, zip_code, actual_control_id_begin_date, actual_control_id_end_date, id_begin_date, id_end_date, updating_time, legp_id_end_date, legp_id_begin_date, open_date, setup_date, client_class, register_capital, register_capital_currency, assert_manager_id_end_date, transactor_id_end_date, src_industry_code, src_occupation_code, contact_name, client_status, institution_type, resident_address, risk_level, ctrl_shareholder_name, ctrl_shareholder_id_no, ctrl_shareholder_id_type, ctrl_shareholder_type, legp_id_no, legp_id_type, work_unit_address, transactor_id_begin_date, ctrl_shareholder_id_end_date, principal_id_end_date, region_code, enterprise_type, benefit_id_end_date, client_short_name, product_due_date, client_source_flag) VALUES (20211208, 'HS0005440521', '长江艾森投资管理股份有限公司', NULL, NULL, 0, NULL, ' ', NULL, '', '0', NULL, NULL, '0', '浙江省杭州市西湖区', '002', NULL, NULL, NULL, NULL, 19800102, NULL, NULL, NULL, NULL, NULL, NULL, '钱可可', NULL, '02', '19940622jbrZJDM00001000000000000', NULL, NULL, NULL, NULL, NULL, NULL, '长江艾森投资管理股份有限公司', '202304140002', '99', '12345@163.com', NULL, '浙江省杭州市西湖区', 'FSH20211206004', '32', NULL, NULL, NULL, 'food', ' ', NULL, NULL, NULL, '长江艾森投资管理股份有限公司', NULL, NULL, NULL, NULL, NULL, NULL, NULL, ' ', '02400589515', NULL, NULL, ' ', 'HS', '25118548124', NULL, NULL, ' ', NULL, NULL, 19000101, 19000101, 19000101, NULL, '', NULL, 19000101, 20211207, 19000101, NULL, 0.0000, ' ', 0, 0, 'food', NULL, ' ', ' ', ' ', ' ', 0, ' ', ' ', ' ', ' ', NULL, ' ', ' ', 0, 0, 0, ' ', ' ', 0, ' ', 0, '0')"
    sql_change = sqlChange(sql)
    sql_change.remove_time()